package com.aegean.tool;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyTools {
	public static int strToint(String str) {
		if (str == null || str.equals(""))
			str = "0";
		int i = 0;
		try {
			i = Integer.parseInt(str);
		} catch (NumberFormatException e) {
			i = 0;
			e.printStackTrace();

		}
		return i;

	}

	public static String toChinese(String str) {
		if (str == null)
			str = "";
		try {
			str = new String(str.getBytes("ISO-8859-1"), "UTF-8").trim();

		} catch (UnsupportedEncodingException e) {
			str = "";
			e.getStackTrace();
		}
		return str;
	}

	public static String toGB2312(String str) {
		if (str == null)
			str = "";
		try {
			str = new String(str.getBytes("ISO-8859-1"), "GB2312").trim();

		} catch (UnsupportedEncodingException e) {
			str = "";
			e.getStackTrace();
		}
		return str;
	}

	public static java.util.Date toDate(String str) {
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		java.util.Date date = null;
		if (str == null)
			str = "";
		try {
			date = bartDateFormat.parse(str.trim());
		} catch (Exception e) {
			e.getStackTrace();
		}
		return date;
	}

	public static String toDateString(java.util.Date date) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String time = df.format(date);
		return time;
	}
	public static String toDateString2(java.util.Date date) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = df.format(date);
		return time;
	}

	public static java.util.Date toTime(String str) {
		SimpleDateFormat bartDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd hh:mm");
		java.util.Date date = null;
		if (str == null)
			str = "";
		try {
			date = bartDateFormat.parse(str.trim());
		} catch (Exception e) {
			e.getStackTrace();
		}
		return date;
	}

	public static String toTimeString(java.util.Date date) {
		SimpleDateFormat df = new SimpleDateFormat("hh:mm");
		String time = df.format(date);
		return time;
	}
}
